<template>
  <div class="newsIfo-container">
      <h3 class="title">{{newsInfo.title}}</h3>
      <p class="subtitle">
          <span>发表时间:{{newsInfo.add_time}}</span>
          <span>点击:{{newsInfo.click}}次</span>
      </p>
      <hr>

      <div class="content" v-html="newsInfo.content"></div>
        <!-- 父组件想子组件传值 -->
      <comment-box :id="this.id"></comment-box>
  </div>
</template>

<script>
import {Toast} from 'mint-ui';
import comment from '../subcomment/comments.vue';

export default {
  data(){
      return{
        id:this.$route.params.id, //将URL地址中传递过来的id值挂载到data上，方便后面的使用
        newsInfo:{}
      }
  },
  created(){
      this.getNewsIfo();
  },
  methods:{
    //根据获取的到的id值获取页面内容
    getNewsIfo(){
        this.$http.get('api/getnew/'+this.id).then(result=>{
            if(result.body.status === 0){
                this.newsInfo = result.body.message[0];
            }else{
                Toast('新闻获取失败');
            }
        })
    }
  },
  components:{
      "comment-box":comment
  }
}
</script>

<style lang="scss">
.newsIfo-container{
    padding: 4px;
    padding-bottom: 50px;
    .title{
        color:red;
        text-align:center;
    }
    .subtitle{
        font-size: 12px;
        color: #226aff;
        display: flex;
        justify-content: space-between;
    }
    .content {
        // padding-bottom: 50px;
        img {
            width:100%;
        }
    }
}
</style>


